@extends('admin.layout.common')
@section('content')
    <link rel="stylesheet" href="{{asset('/css/finance/user-inform-statement.css')}}">
    <link rel="stylesheet" href="{{asset('/images/iconfont_sanka/iconfont.css')}}">
    <link rel="stylesheet" href="{{asset('/css/app.css')}}">
    <div class="content">
        <h1 class="h1">财务记账中心</h1>
        <!-- 公共结束 -->
        <div class="input-box">
            <form action="">
                <label for="">SP查找
                    <select name="platform_id" id="">
                        <option value="">SP公司选择</option>
                        @foreach($search['company'] as $v)
                            <option value="{{$v['id']}}">{{$v['platform']}}</option>
                        @endforeach
                    </select>
                    <select name="type" id="">
                        <option value="">收入类型选择</option>
                        @foreach($search['type'] as $v)
                            <option value="{{$v['type']}}">{{$v['type']}}</option>
                        @endforeach
                    </select>
                </label>
                <button type="sbumit">查找</button>
            </form>
        </div>
        <div class="table-box">
            @include('flash::message')
            <table border="1">
                <tr>
                    <th>ID</th>
                    <th>SP公司</th>
                    <th>分账类型</th>
                    <th>SP收入</th>
                    <th>收入报表</th>
                    <th>操作</th>
                </tr>
                @foreach($list as $k => $v)
                    <form id="{{$k}}"
                          action="@if($v['status'] == 0){{url('/admin/spInput').'/'.$year.'/'.$month}}@else{{url('/admin/delInputById')}}@endif"
                          method="post"
                          enctype="multipart/form-data">
                        {{csrf_field()}}
                        <input name="id" type="hidden" value="{{$v['id']}}">
                        @if($v['status'] == 0)
                            <tr>
                                <td>{{$v['id']}}</td>
                                <td>{{$v['platform']['platform']}}</td>
                                <td>{{$v['type']['type']}}</td>
                                <td><input name="amount" type="number" required></td>
                                <td>
                                    <input name="excel" type="file" class="upload_file_{{$k}}" name="file_addr"
                                           onchange="doChange(this, '{{$k}}')" style="display:none;"/>
                                    <input class="photoCover_{{$k}}" maxlength="0" placeholder="请上传excel" type="text"
                                           required>
                                    <button type="button" onclick="$('input[class=upload_file_{{$k}}]').click();"
                                            class="layui-btn layui-btn-primary" value=""
                                            style="background:#fff;border:1px solid #ccc;color:#333;width:80px;">上传
                                    </button>
                                </td>
                                <td>
                                    <button type="submit" class="layui-btn layui-btn-primary check" style="width:80px;">
                                        <i class="iconfont icon">&#xe7a5;</i></button>
                                </td>
                            </tr>
                        @else
                            <tr>
                                <td>{{$v['id']}}</td>
                                <td>{{$v['platform']['platform']}}</td>
                                <td>{{$v['type']['type']}}</td>
                                <td><input name="amount" type="number" value="{{$v['amount']}}"></td>
                                <td>
                                    <input name="excel" type="file" class="upload_file_{{$k}}" name="file_addr"
                                           onchange="doChange(this, '{{$k}}')" style="display:none;"/>
                                    <input class="photoCover_{{$k}}" maxlength="0" placeholder="请上传协议" type="text"
                                           required value="{{$v['original_name']}}">
                                    <button type="button" onclick="$('input[class=upload_file_{{$k}}]').click();"
                                            class="layui-btn layui-btn-primary" value=""
                                            style="background:#fff;border:1px solid #ccc;color:#333;width:80px;">上传
                                    </button>
                                </td>
                                <td>
                                    <button formId="{{$k}}" type="button" class="layui-btn layui-btn-primary del"
                                            style="background:#fff;border:1px solid #ccc;color:#333;width:80px;">
                                        更改删除
                                    </button>
                                </td>
                            </tr>
                        @endif
                    </form>
                @endforeach
            </table>
            {{$list->appends(['platform_id' => $_GET['platform_id'] ?? '', 'type' => $_GET['type'] ?? ''])->links()}}
        </div>
    </div>
    <script>
      // 提交文件
      function doChange(file, k) {
        var upload_file = $.trim($(".upload_file_" + k).val());    //获取上传文件
        $('.photoCover_' + k).val(upload_file);     //赋值给自定义input框
        $('.photoCover_' + k).show();
      }

      $(function () {
        // 更改删除弹窗
        $(".del").on("click", function () {
          let form = $(this).attr('formId');
          layer.confirm('删除后，本月数据需重新上传！', {
            btn: ['确认', '取消'] //按钮
          }, function () {
            $('#' + form).submit();
            layer.msg('请稍后', {icon: 1});
          }, function () {
            layer.msg('已取消', {
              time: 2000, //20s后自动关闭
            });
          });
        })
      })
    </script>
@endsection